﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Common.Eventing
{
    /// <summary>
    /// Defines the interface for a component that can broker events among a 
    /// set of publishers and subscribers.
    /// </summary>
    public interface IEventBroker
    {
        /// <summary>
        /// Gets the set of subscriptions being managed by the event broker.
        /// </summary>
        IEnumerable<IEventHandler> Subscriptions { get; }


        /// <summary>
        /// Gets the set of subscriptions for the given event type.
        /// </summary>
        /// <param name="eventType"></param>
        /// <returns></returns>
        IEnumerable<IEventHandler> GetSubscriptionsFor(Type eventType);

        /// <summary>
        /// Subscribes to an event.
        /// </summary>
        /// <param name="handler">The subscription to add.</param>
        void Subscribe(IEventHandler handler);

        /// <summary>
        /// Unsubscribes from an event.
        /// </summary>
        /// <param name="handler">The subscription to remove.</param>
        void Unsubscribe(IEventHandler handler);

        /// <summary>
        /// Publishes an event.
        /// </summary>
        /// <param name="eventMessage">The event to publish</param>
        void Publish(object eventMessage);
    }
}
